<template>
  <div class="shoplist-content">
    <van-cell-group>
      <van-field v-model="addtime" placeholder="请选择开始时间" @focus="showadd = true"/>
      <van-field v-model="endtime" placeholder="请选择结束时间" @focus="showend = true"/>
    </van-cell-group>
    <div class="searchbtn" @click="Suk_search">时间查询</div>
    <van-popup v-model="showadd" position="bottom">
      <van-datetime-picker
        v-model="addDate"
        type="date"
        @confirm="Suk_checkaddtime"
        @cancel="showadd = false"
      />
    </van-popup>
    <van-popup v-model="showend" position="bottom">
      <van-datetime-picker
        v-model="endDate"
        type="date"
        @confirm="Suk_checkendtime"
        @cancel="showadd = false"
      />
    </van-popup>
    <div class="shoplist" v-for="(item,index) in list" :key="index">
      <div>{{ item.logName }}</div>
      <div>客户：{{ item.userName }}</div>
      <div>订单时间：{{ item.addtime }}</div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addDate: new Date(),
      endDate: new Date(),
      addtime: null,
      endtime: null,
      showadd: false,
      showend: false,
      list: []
    };
  },
  beforeCreate: function() {
    //创建前
  },
  activated() {
    this.Suk_getlist();
  },
  created: function() {
    this.Suk_getlist();
    //创建后
  },
  beforeMount: function() {
    //挂载前
  },
  mounted: function() {
    //挂载后
  },
  beforeUpdate: function() {
    //更新前
  },
  update: function() {
    //更新后
  },
  methods: {
    Suk_search() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      let Sukdata = {
        dinId: localStorage.getItem("userid"),
        addtime: that.addtime,
        time: that.endtime
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/log/queryDin", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            console.log(res.data);
            if (res.data.meta.code == 500) {
              that.$toast({
                message: "没有订单！"
              });
              that.list = [];
            }
            if (res.data.meta.code == 200) {
              that.list = res.data.data;
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    Suk_checkaddtime(e) {
      
      let y = e.getFullYear();
      let m = e.getMonth()+1;
      let d = e.getDate();
      console.log(m);
      if (m < 10) {
        m = "0" + m;
      }
      if (d < 10) {
        d = "0" + d;
      }
      this.addtime = y + "-" + m + "-" + d;
      this.showadd = false;
    },
    Suk_checkendtime(e) {
      let y = e.getFullYear();
      let m = e.getMonth()+1;
      let d = e.getDate();
      console.log();
      if (m < 10) {
        m = "0" + m;
      }
      if (d < 10) {
        d = "0" + d;
      }
      this.endtime = y + "-" + m + "-" + d;
      this.showend = false;
    },
    Suk_getlist() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      let Sukdata = {
        dinId: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/log/queryDin", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if(res.data.meta.code==500){
                that.$toast({
                  message:'暂无记录'
                });
              }
            if (res.data.meta.code == 200) {
              console.log(res.data);
              
              that.list = res.data.data;
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.shoplist-content {
  font-size: 0.45rem;
}
.shoplist {
  width: 90%;
  margin: 0 auto;
  padding: 0.3rem 0;
  border-bottom: 1px solid #eee;
}

.searchbtn {
  background: #ff9910;
  display: inline-block;
  padding: 0.1rem 0.2rem;
  color: #fff;
  border-radius: 0.2rem;
  float: right;
  margin-top: 0.2rem;
  margin-right: 0.3rem;
}
</style>